var options = new Array();

function OptionEntity(index){
	
	this.index = index;
	var self = this;
	
	this.create = function(){
		this.option_li = $('<li></li>');
		this.option_index = $('<span id="orderNum'+ index +'" class = "btn btn-primary">'+ index +'</span>');
		this.option_text = $('<input id="itemTitle'+ index +'" type="text" placeholder="奖项名称"  class="m-wrap small required"/>');
		this.option_text1 = $('<input id="lotteryName'+ index +'" type="text" placeholder="奖品名称" value="" class="m-wrap small required"/>');
		this.option_text2 = $('<input id="amount'+ index +'" type="text" placeholder="奖品数量" onkeyup="value=value.replace(/[^\1-9\]/g,``)" class="m-wrap small required"/>');
		this.option_delete = $('<a class="btn btn-danger">删除</a>'); 

		this.option_li.append(this.option_index);
		this.option_li.append(this.option_text);
		this.option_li.append(this.option_text1);
		this.option_li.append(this.option_text2);
		this.option_li.append(this.option_delete);
		options.push(self);
	};
	this.deleteOption = function(){
		if(options.length < 2){
			layer.tips("奖项信息不得少于一项！", "#delete", {
				tips:[2, '#c00'],
			})
			return;
		}
		self.option_li.remove();
		for(var i = 0; i < options.length; i++){
			if((i+1) > self.index){
				options[i].index = options[i].index - 1;
				options[i].option_index.html(options[i].index);
				options[i].option_text.attr("name","option_" + options[i].index );
			}
		}
		options.splice((self.index - 1), 1);
	};
	
	this.create();
	this.option_delete.on("click", self.deleteOption);
}